package com.yenlien.traceyun.business.service;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.dao.WexinSubDao;
import com.yenlien.traceyun.business.entity.Subpackage;
import com.yenlien.traceyun.business.entity.WexinSub;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: bigwangy@sina.com
 * @create: 2021-03-10
 * @description:
 **/
@Service
public class WexinSubService {

    @Autowired
    private WexinSubDao wexinSubDao;

    @Autowired
    private PlantSubPackService plantSubPackService;

    @Transactional(rollbackFor = RuntimeException.class)
    public void wexinSub(JSONObject params) {
        Subpackage subpackage = params.getJSONObject("subpackage").toJavaObject(Subpackage.class);
        WexinSub wexinSub = params.getJSONObject("wexinSub").toJavaObject(WexinSub.class);
        Subpackage persistent = plantSubPackService.save(subpackage);
        wexinSub.setCompanyId(persistent.getCompanyId());
        wexinSub.setSubId(persistent.getId());
        wexinSubDao.save(wexinSub);
    }
}
